﻿using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;

namespace CMS.Common.Validation
{
    public class CMSRequired : RequiredAttribute, IClientValidatable
    {
        public CMSRequired()
        {
            ErrorMessage = @"{0} is required.";
        }

        public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
        {
            yield return new ModelClientValidationRule
            {
                ErrorMessage = string.Format(ErrorMessage, metadata.DisplayName),
                ValidationType = "required"
            };
        }
    }
}